function callback123(json) {
	return json;
}



var tgd = tgd || {};
tgd.Services = tgd.Services || {};
tgd.Services.Media = tgd.Services.Media || {};

tgd.Services.Media.Library = function () {
	tgd.Services.Media.Library.prototype.log = function(txt) {
		var now = new Date();
		var div = document.createElement("div");
		var msgLog = document.getElementById("log");
		div.innerHTML = "<span class='date'>" + now.getHours() + ":" + (now.getMinutes() < 10 ? "0" : "") + now.getMinutes() + ":" + (now.getSeconds() < 10 ? "0" : "") + now.getSeconds() + "</span> " + txt;
		msgLog.insertBefore(div, (msgLog.hasChildNodes() ? msgLog.childNodes[0] : null));
	}

	this.log("tgd.Services.Media.Library object created");

	this.onDelete = null;
	this.onRefresh = null;
	this.onGet = null;
	this.onPost = null;
	this.onPut = null;
	this.Name = "";
	this.CreatedBy = "tgd";
	this.DateCreated = null;
	this.ID = -1;

	if (tgd.Services.Media.Library._initialized === undefined) {

		tgd.Services.Media.Library.prototype.refresh = function() {
			this.log("GET all libraries");
			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self._data = eval(self._request.responseText);
					self.onRefresh();
				}
			}
			this._request.open("GET", "http://timmytooltastix.appspot.com/libraries", true);
			this._request.setRequestHeader("If-Modified-Since", "Thu, 17 Jun 1982 00:00:00 GMT");  //IE caching
			//todo:  send headers as needed
			this._request.send(null);
		}

		tgd.Services.Media.Library.prototype.load = function() {
			this.log("GET the data for [" + this.ID + "]");
			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self._data = eval(self._request.responseText);
					self.ID = self._data[0].ID;  //todo: have tim get rid of this array
					self.Name = self._data[0].Name;
					self.DateCreated = self._data[0].DateCreated;
					self.CreatedBy = self._data[0].CreatedBy;
					self.onGet();
				}
			}
			this._request.open("GET", "http://timmytooltastix.appspot.com/libraries/" + this.ID, true);
			this._request.setRequestHeader("If-Modified-Since", "Thu, 17 Jun 1982 00:00:00 GMT");  //IE caching
			//todo:  send headers as needed
			this._request.send(null);
		}

		tgd.Services.Media.Library.prototype.save = function() {
			this.log("POST new library with name = [" + this.Name + "]");
			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					if (self._request.status == 200) {
						self.onPost();
					} else {
						self.log("POST library w/ Name [" + self.Name + "] message returned " + self._request.status + "   " + self._request.statusText);
					}
				}
			}
			this._request.open("POST", "http://timmytooltastix.appspot.com/libraries", true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send("Name=" + this.Name + "&User=" + this.CreatedBy);
		}

		tgd.Services.Media.Library.prototype.update = function() {
			this.log("PUT update name of library [" + this.ID  + "] to [" + this.Name + "] by [" + this.CreatedBy + "]");

			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self.onPut();
				}
			}
			this._request.open("PUT", "http://timmytooltastix.appspot.com/libraries/" + this.ID, true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send("Name=" + this.Name);
		}

		tgd.Services.Media.Library.prototype.remove = function() {
			this.log("DELETE library w/ id = [" + this.ID + "]");

			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self.onDelete();
				}
			}
			this._request.open("DELETE", "http://timmytooltastix.appspot.com/libraries/" + this.ID, true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send();
		}

		tgd.Services.Media.Library._initialized = true;
	}
}
